/**
 * admui-basic v2.1.0 (http://www.admui.com/)
 * Copyright 2015-2019 Admui Team
 * Licensed under the Admui License 1.1 (http://www.admui.com/about/license)
 */
(function() {
  'use strict';

  window.App.extend({
    run: function() {
      // 新建日历按钮初始化
      var actionBtn = $('.site-action')
        .actionBtn({
          toggleSelector: '.list-group-item',
          listSelector: '.site-action-buttons'
        })
        .data('actionBtn');

      // 为当前选中笔记显示编辑按钮
      actionBtn.show();

      // 按钮显示 | 隐藏
      $(document).on('click', '.site-action-toggle', function(e) {
        if (!$('.list-group-item').hasClass('active')) {
          $('#addNewNote').modal('show');

          e.stopPropagation();
        } else {
          $('.list-group-item').removeClass('active');
          actionBtn.hide();
        }
      });

      // 选择笔记操作
      $(document).on('click', '.list-group-item', function() {
        var $item = $(this);

        $item
          .addClass('active')
          .siblings()
          .removeClass('active');

        $item.hasClass('active') && actionBtn.show();
      });
    }
  });

  $(function() {
    window.App.run();
  });
})();
